if (sessionStorage.getItem('oid') == null) {
	$('.list-cont')[0].innerHTML = '';
	$('#shifu').text('');
	$('#name').val('');
	$('#phone').val('');
	$('#address').val('');
	layer.msg('暂无', { icon: 0, time: 800 }, function () {
		// localStorage.href = './login.html';
	});
} else {
	$('.list-cont')[0].innerHTML = '';
	$.ajax({
		url: 'http://localhost:3000/admin/queryOrderById',
		method: 'GET',
		async: false,
		data: { order_id: sessionStorage.getItem('oid') },
		success: function (data) {
			var intro = '';
			console.log(data.data[0].goods[1]);
			for (var i = 0; i < data.data[0].goods.length; i++) {
				$.ajax({
					url: 'http://localhost:3000/admin/getGoodsById',
					method: 'GET',
					async: false,
					data: { id: data.data[0].goods[i].goodId },
					success: function (data) {
						intro = data.data.intro;
					}
				});
				$('.list-cont')[0].innerHTML += `
          <ul>
          <li class="li1">
            <dl>
            <a href="javascript:void(0)" onclick="datai(${data.data[0].goods[i].goodId})">
                <dt><img src="http://localhost:3000/update/${data.data[0].goods[i].cover}"></dt>
                <dd class="goodsname" style="padding-top: 36px;">${data.data[0].goods[i].goodName}</dd>
                <dd class="goods-des">${intro}</dd>
              </a>
            </dl>
          </li>
          <li class="li3">￥<span>${data.data[0].goods[i].price}</span></li>
          <li class="li4">x<span>${data.data[0].goods[i].num}</span></li>
          <li class="li5">￥<span>${data.data[0].goods[i].price * data.data[0].goods[i].num}</span></li>
        </ul>     
      `;
			}
			$('#shifu').text(data.data[0].total);
			$('#name').val(data.data[0].name);
			$('#phone').val(data.data[0].phone);
			$('#address').val(data.data[0].address);
		}
	});
}
var paytype = 1; //默认为1
$('#payway .payway-cont .way').on('click', function () {
	$(this).addClass('active').siblings().removeClass('active');
	paytype = $(this).attr('data');
});

$('#tijiao').click(function () {
	$.ajax({
		url: 'http://localhost:3000/admin/orderPay',
		async: false,
		method: 'POST',
		data: { order_id: sessionStorage.getItem('oid'), paytype: paytype, name: $('#name').val(), phone: $('#phone').val(), address: $('#address').val() },
		success: function (data) {
			if (data.state == 1) {
				sessionStorage.removeItem('oid');
				layer.msg('支付成功', { icon: 1, time: 800 }, function () {
					location.href = './payok.html';
				});
			} else {
				layer.msg(data.msg, { icon: 0, time: 800 }, function () {
					location.reload();
				});
			}
		}
	});
});
